import { ReactNode } from 'react';
import styles from './index.module.scss';
import classNames from 'classnames';

// Props 高级写法，继承所有 input 属性
interface Props
  extends React.DetailedHTMLProps<
    React.InputHTMLAttributes<HTMLInputElement>,
    HTMLInputElement
  > {
  className?: string;
  // 右边按钮
  extra?: ReactNode;
  // 错误信息
  errorMsg?: string;
}

export default function Input({ className, extra, errorMsg, ...rest }: Props) {
  return (
    <div className={styles.root}>
      <input className={classNames('input', className)} {...rest} />
      {extra && <div className="extra"> {extra} </div>}
      {errorMsg && <div className="validate">{errorMsg}</div>}
    </div>
  );
}
